
class nRoomBuff{
public:

	nRoomBuff();
   ~nRoomBuff();
   
    Image BImage;
    u8 SDirty;
	u8 Dirty;
	u8 X;
    u8 Y;
    u8 newX;
    u8 newY;
    u8 CompMode;
    u16 TileBuf2D[0x10000];

	RECT DrawRect;
	
    long ThisCompsize;
    long ThisDecompedpageSize;
    long TilePageCompsize;
    long size;
    long oSize;
};
class cCopyData{
   //Currenly only support string to int
public:
    
	cCopyData();
   ~cCopyData();
    int Copy (int Width,RECT data,u16* pnt);
	int Paste(u16 *pnt);
	void Dump();
private:
	RECT  DataHold;//Configuration of data
	std::vector<u16> buffer;
	int CopyWidth;
	int size;
};
struct sUndo{
u16* copyAddress;
std::vector<u16> buffer;


};
class cUndoBuffer{//Resizing rooms will invalidate undobuffer
public:

	~cUndoBuffer();
	cUndoBuffer();
	int Set(u32 size,u16* Layer);
    int Undo();
    sUndo UndoBuffer[16];
	int UndoNum;
    int MoveUp();

};

class sCombo{
public:
	sCombo();
	~sCombo();
	long GetListIndex();
	int cClear();
	int Clear();
	int Click();
    int SetListIndex(int Value);
	int Additem(char* string);
	int sList(int index);
	int Init(HWND sComboHwnd);
	int Disable();
	int Enable();
HWND thishwnd();
private:
	HWND hCombo;

};
class sList{
public:
	sList();
	~sList();
	long GetListIndex();
	int cClear();
	int Clear();
	int Click();
    int SetListIndex(int Value);
	int Additem(char* string);
	int sListStrings(int index);
	int Init(HWND sListHwnd);
	int Disable();
	int Enable();
HWND thishwnd();
private:
	HWND hCombo;

};
class sChecks{
public:
	sChecks();
   ~sChecks();
int cClear();

int SetCnt(HWND hwnd);

int value();

int value(u8 Val);
int sChecks::State(bool flag);

int sChecks::State();

	HWND check;

};

struct RectBuff{
long Y,X;
 long StartX ;
 long StartY ;
 long oX;
 long oY;
 long EndX;
 long EndY;
 u8 Started;
};


struct sDoor{ 
  u8 DoorType;
  u8 OwnerRoom;
  u8 XEntrance;
  u8 DWidth;
  u8 YEntrance;
  u8 DHeight;
  u8 DestDoor;
  u8 ExitDoorLength;
  u8 u1;
  u8 u2;
  u8 u3;
  u8 u4;
};

struct DoorStruct{
 u8 DoorCount;
 u8 DoorNotes[0xFF];
};





struct sctype{
u8 xStart;
u8 xEnd;
u8 yStart;
u8 yEnd;
};

class Scroller{
public:
     Scroller();
	~Scroller();
u8 Room;
u8 Number;
sctype Scrolls[0xFF];
};

//EXT scroll As Scroller
class cScroll{
public:

int      CreateScroll(sctype *thisscroll);
private:

	HWND xStart;
	HWND hWidth;
	HWND yStart;
	HWND hHeight;
	RECT curRect;
};


class stxts{
   //Currenly only support string to int
public:

	stxts();
   ~stxts();
int SetHwnd(HWND hwnd);
int GetText();
int SetText(char* string);
private:
	HWND thisHwnd;
	
};


struct nEnemies{
    u8 Y;
    u8 X;
    u8 Creature;
};
struct MousePointer{
u8 sX;
u8 sY;
u8 eX;
u8 eY;
u8 cX;
u8 cY;
u8 nX;
u8 nY;
u8 uX;
u8 uY;
u8 Width;
u8 Height;

};


struct  nEnemyList{
   u8 max;
   nEnemies Enemies[0x20];
};


struct CompHeader{
   u8 check_ten;       //Check byte should be 0x10 for lz
   u8  l3;        //length = l3*0x10000 + l2*0x100 + l1
   u8  l2;
   u8  l1;
};

struct sprite_entry{
    u8 sprtype;
    u8 sprdetail;
};

struct  EncodedOAM {
	//OAM0 Props
	// 0-7   Y-Coordinate
	// 8     Rotation/Scaling Flag
	//When Rotation/Scaling used (Attribute 0, bit 8 set):
	//    9     Double-Size Flag     (0=Normal, 1=Double)
	//  When Rotation/Scaling not used (Attribute 0, bit 8 cleared):
	// 9         OBJ Disable(0 = Normal, 1 = Not displayed)
	//10-11 OBJ Mode  (0=Normal, 1=Semi-Transparent, 2=OBJ Window, 3=Prohibited)
	//12    OBJ Mosaic
	//13    Colors/Palettes
	//14-15 OBJ Shape

	//OAM1 Props
	//0-8   X-Coordinate           (0-511)
	//When Rotation/Scaling used (Attribute 0, bit 8 set): 9-13  Rotation/Scaling Parameter Selection (0-31)
	//When Rotation/Scaling not used (Attribute 0, bit 8 cleared):
	//9-11  Not used
	//12        Horizontal Flip(0 = Normal, 1 = Mirrored)
	//13        Vertical Flip(0 = Normal, 1 = Mirrored)
	//14-15 OBJ Size               (0..3, depends on OBJ Shape, see Attr 0)
	//          Size  Square   Horizontal  Vertical
	//          0     8x8      16x8        8x16
	//          1     16x16    32x8        8x32
	//          2     32x32    32x16       16x32
	//          3     64x64    64x32       32x64

	//OAM2 Props
	//0-9   Character Name          (0-1023=Tile Number)
	//10-11 Priority relative to BG (0-3; 0=Highest)
	//12-15 Palette Number   (0-15) (Not used in 256 color/1 palette mode)
	unsigned short OAM0;
	unsigned short OAM1;
	unsigned short OAM2;


};
#define oWidth 0
#define oHeight  1
struct DecodedOAM {
	u8 yCoord;
	u8 objRot;
	u8 DSaOD;
	u8 ObjMode;
	u8 ObjMosiac;
	u8 Paltype;
	u16 ObjShape;
	u16 xCoord;
	u8 rotation;
	u8 HorizontalFlip;
	u8 VerticalFlip;
	u8 ObjSize;
	u16 TileNumber;
	u32 priority;
	u8 Palette;
};

struct OverAllOAM {

	EncodedOAM enOAM;
	DecodedOAM deOAM; 
};

struct sSpriteTable {
	u32 Pointers;
	u32 Frame;
	
};


struct sTileMacros{
	   u8 Clipdata;
	   u16 ForegroundTile;
	   u16 BacklayerTile;
};




struct tBlock{
    u16 Tile;
	u16  HFlip;
	u16  VFlip;
	u16  Pal;
};


class lz77
{
public:

	lz77(void);
	~lz77(void);
     
	u8 UnCmpData[3][2048*4];
	u8 UnCmpPal[5][32*4];
	u8 smallpal[2];
	u8 filedata[170000];
	int filedatapos;


	int length;
	//u16 unCmpSize;

	void BIOS_LZ77UnCompWram();

	void BIOS_LZ77CompWram(u8 data[],int Size, int compression); //


	u32 CPUReadMemory(int source);
	u8 CPUReadByte(int source);
	void CPUWriteByte(unsigned long a, unsigned char b);
	void CPUWriteMemory(int adress, u32 data);
    
	u32 source;
	


	u8 cFile[170000];
	
};

class cTED{

public:
cTED();
~cTED();
HWND tMain;
HWND textpic;
sList cOffsets;
int Create();
char curtext[0x1000];
int DecodeText(u32 offset);
int LoadTable();
Image Text;
int CreateTextpicTileImage();
int Draw();
int EncodeText();
TileBuffer Tiles;
int BiCat(u16* val, char* character);
u32 ZMOffsets[16][0x200];
u32 Offsets[0x200];
sCombo cboTxt;
char table[0xFFFF][64];
u16  binarystring[1024];
u8    Graphics[0xF000];
long   FontPal[0x200];
long   txtlength;
int    ResetList();
char pixelflag;
};


class mmD{

public:

	mmD();
   ~mmD();

    HWND hwndMiniMap;
	HWND hwndMiniTileset;
	sCombo  MFMap;
	int Create();//Sets colors and arrays up
    int Clear();//Clears palette and graphics
	sCombo  cboPalette;
	sCombo  cboMArea;
	Image   Tileset;
	Image   Map;
	long   MapList[0xB];
	u8     MZMTilesetGraphics[0x3000];
	u8    MFTilesetGraphics[0x4000];
	long    MFPalette[0x400];
    long    MZMPalette[0x400];
	u16*    RawMap;
	TileBuffer ts;
	int DecompressMap();
	int Destroy();
    int CreateMiniMapImage(int Width,int Height);
	int CreateMiniMapTileImage(int Width,int Height);
    int DrawTileset();
	int DrawMap();
	int SaveMap();
	u32 DSize;
	u16 curtile;
	sChecks Vert;
	sChecks Horz;
	
private:
    int Zero();//Will 0 out every erray and return the average to make sure it's all 0
    
};

struct ZMS{


u16 health;
u16 Dmg;
u16 resistance;
u16 unknown;
u16 smallHP;
u16 largehp;
u16 missiles;
u16 supermissiles;
u16 PowerBombs;

};
struct MFS{
u16 Health;
u16 Damage;
u16 unknownDamage;
u8 resistance;
u8  unknown6;
u16 unknown1;
u16 unknown2;
u16 unknown3;
u16 end;//Always 0?
};
struct SprGBuf{
	int id;
RECT  Borders;
Image PreviewSprite;
long  PreviewPal[512];
u8    PreRAM[0x8000];//Funny name XD
u16 PartNo;              //Currently Stoned during writing of preview stuff
OverAllOAM  OAM[512];
TileBuffer  Tiles;
int maxparts;
u8 details;
u16 palsize;
u32 graphicsize;
};
class cStatEd{
public:
	cStatEd();
   
	~cStatEd();
    int Switch();
	int InitDialog();
	int SetUpForZM();
	int SetUpForMF();
	int LoadSprite();
	int SetupPreview();
	int SaveSprite();
	SprGBuf SpritePreview;
	sList   SpriteList;
	ZMS     ZMSprite;
	MFS     FusionSprite;
	HWND me;
	HWND Health;
	HWND Damage;
	sCombo Res1;
	sCombo Res2;
	//ZM stuff
	HWND  shp;
	HWND  lhp;
	HWND  m;
	HWND  sm;
	HWND  pb;
	//MF
	HWND  u1;
	HWND  u2;
	HWND  u3;
	HWND  ud;

};

struct sSpritev{
	u8 RAM[0x10000];
};



struct GFXData{
    u32  RomPointer;
	u32  MemDst;
};

struct PalData{
    u32 RomPointer;
	u32 MemDst;
	u32 Size;
};

class cSSE{
public:
HWND  me;
sList SpriteSets;
sList Population;
Image Tiles;
sCombo cboDetail;
HWND  PalView;
HWND  SprView;
int   Create();
SprGBuf SpritePreview;
SprGBuf Ingame;
u32     GUT;
u32     PUT;
int SlightChange();
int GetSet();
int DecodeSet();
int LoadSprite();
int SetupPreview(SprGBuf* SprG);
u32 usedGFX;
u32 usedPAL;
u8  graphics[0x8000];
GFXData gfxinfo[16];  
PalData palinfo[16]; 
sprite_entry spriteset[15];
long pal[512];
int SetInfo();
TileBuffer SprGraphics;
int CreateSpriteWindow();
int CreatePalWindow();
u8 total;
};

class cOAMEdit{
public: 
cOAMEdit();
~cOAMEdit();
 sCombo cboPal;
 sCombo cboFrames;
 sCombo cboPartNo;
 sCombo cboShapes;
 sCombo cboSizes;//Changes based on cboShape
 sList  lstSprite;
 sChecks VChk;
 sChecks HChk;
 HWND   hwndSpritePreview;
 HWND   hwndTiles;
 HWND   hwndPal;
 HWND   me;
 Image  Tiles;
 Image  Sprite; 
 SprGBuf  SGBSpr;
 sSpriteTable   FrameTable[0xFF];
 RECT  rPart;
 int maxframe;
 int CreatePalHWND();
 int CreateTileHWND();
 int CreateSpriteHWND();
 int UpdateTiles();
 int UpdatePal();
 int UpdateSprite();
 int DrawSelObj(HDC hdc);
 int ExportPal();
 int ImportPal();
 int ExportGraphics();
 int ImportGraphics();
 int AnimateSprite();
 int GetSpriteData();
 int ChangeFrame();
 int Create();
 int UpdateSize();
 int GetFrames();
 int SetFrames();
 int SetParts();
 int SetupPreview();

};

class cClipboard{
public: 
	cClipboard();
	~cClipboard();
	u8 copy;
	u8 curclip;
    sCombo cboCurClip;
	u16 thisclipboard[16][256][4];
    Image  cbi[16];
    HWND me;
	HWND cb;
	
	int DrawSlots();
	int CheckforBlanks(HDC hdc);
	int CopyTiles(LPARAM lParam,int surface =0);
	int Create();
	int Erase();
	int Erase(int board, int slot);
    int inuse;
	int CreatePic();
};




struct RECORD{
	u8	*data;
	u32	width;
	u32	height;
};

class wndCPal{
HWND me;
long epal[256];
int  refreshWnd(HWND hwnd);
int  hascontrol;
int  GiveControl();


};


class wndBGImport{
public:
 wndBGImport();
~wndBGImport();
 HWND me;
 Image Pic;
 long  PCPal[256];
 short GPal[256];
 u8    buffer[64000];
 u8    palpos;
 u16   tilemap[32000];

 u16   palsize;
 u32   tilesize;
 u32   mapsize;
 int   Type; 
 RECT  map;//Left Will the position and right will be the size of the palette
           //top will be starting point of tiles in RAM
 sCombo	 cboPal;
 TileBuffer Tiles;
 int   picloaded;
 char  FileString[1024];
 int   MakeFiles();
 int   LoadFiles();
 int   DelFiles();
 char  picname[1024];
 int   Draw();
 int   FillCustBG();
 int   SaveCustBGROM();
 int   SaveCustTileset();
 int   pW;
 int   pH;
 int   FillOutArray(u8* array);

};

class clsScroll{
public:
long curpos;
int max;
clsScroll();
~clsScroll();
HWND me; 
int vert;
int UpdateScroll(WPARAM how);
int create(HWND hwnd, int isvert, int max);
int ChangeScrollbars();
};

